#!/usr/bin/env python
# vim: set filetype=python expandtab tabstop=2 shiftwidth=2 autoindent smartindent:
# -*- coding: utf-8 -*-
#
from google.appengine.api import urlfetch
from google.appengine.ext import webapp

# test fetch url
class Fetch(webapp.RequestHandler):
  def get(self):
    self.response.out.write("""
      <html>
        <head>Fetch A Url</head>        
        <body>
          <form action="/fetchme" enctype="multipart/form-data" method="post">
          <div><label>Plese input a valid url(begin with http):</label></div>
          <div><input type="text" name="url"/></div>
          <div><input type="submit" value="Fetch me!"></div>
        </body>
      </html>""")
      
class Fetchme(webapp.RequestHandler):
  def post(self):
    url = self.request.get("url")
    result = urlfetch.fetch(url)
    if result.status_code == 200:
      self.response.out.write(result.content)
    else :
      self.response.out.write(str(result.headers))
    
